package im.oen.boot.common.exception;

import im.oen.boot.common.constant.OenCode;
import im.oen.boot.common.data.Code;

/**
 * OEN 通用的顶层异常
 *
 * @author Kevin.Xu
 */
public class OenException extends RuntimeException {

    private final Code error;

    public OenException() {
        super(OenCode.SERVER_ERROR.toString());
        this.error = OenCode.SERVER_ERROR;
    }

    public OenException(Code error) {
        super(error.toString());
        this.error = error;
    }

    public OenException(Throwable error) {
        super(error);
        this.error = new Code(OenCode.SERVER_ERROR, error.getMessage());
    }

    public OenException(Code error, Throwable exception) {
        super(error.toString(), exception);
        this.error = error;
    }

    public Code getErrorCode() {
        return this.error;
    }
}
